package nc.bs.common.util;

import java.lang.reflect.Array;
import java.util.Iterator;
import java.util.Map;

/**
 * @author duanyp1
 * @date 2024/1/18 16:03
 */
public class ObjectUtils {

    public static boolean isEmpty(Object obj) {
        if (null == obj) {
            return true;
        }
        if (obj instanceof CharSequence) {
            return ((CharSequence) obj).length() == 0;
        } else if (obj instanceof Map) {
            return ((Map<?,?>) obj).size() == 0;
        } else if (obj instanceof Iterable) {
            return !((Iterable<?>) obj).iterator().hasNext();
        } else if (obj instanceof Iterator) {
            return !(((Iterator<?>) obj)).hasNext();
        } else if (obj.getClass().isArray()) {
            return Array.getLength(obj) == 0;
        }
        return false;
    }
}
